﻿#include "myserver.h"

MyServer::MyServer():QObject()
{
    connect(&server,SIGNAL(newConnection()),this,SLOT(incomingConnection()));
}

void MyServer::incomingConnection()
{
    myDebug<<"incomingConnection";

    QTcpSocket * socket= server.nextPendingConnection();
    socket->setParent(0);
    SocketThread * thread=new SocketThread(socket);
    socket->moveToThread(thread);
    thread->start();
}

bool MyServer::start()
{
    server.listen(QHostAddress::Any,42000);
    myDebug<<"server start";
    return true;
}

void MyServer::stop()
{
    if(server.isListening())
        server.close();
    myDebug<<"server stop";
}
